﻿using Autofac;
using Microsoft.Extensions.DependencyInjection;
using Serializer.Implementation;
using System;
using System.Collections.Generic;
using System.Text;

namespace Serializer
{
    public static class ContainerBuilderExtensions
    {

        ///// <summary>
        ///// 使用编解码器。
        ///// </summary>
        ///// <typeparam name="T">编解码器工厂实现类型。</typeparam>
        ///// <param name="builder">服务构建者。</param>
        ///// <returns>服务构建者。</returns>
        //public static IServiceBuilder UseCodec<T>(this IServiceBuilder builder) where T : class, ITransportMessageCodecFactory
        //{
        //    var builder = new ContainerBuilder();
        //    builder.Services.RegisterType(typeof(T)).As(typeof(ITransportMessageCodecFactory)).SingleInstance();
        //    return builder;
        //}


        /// <summary>
        /// 使用编解码器。
        /// </summary>
        /// <typeparam name="T">编解码器工厂实现类型。</typeparam>
        /// <param name="builder">服务构建者。</param>
        /// <returns>服务构建者。</returns>
        public static object UseMessagePackCode(this ContainerBuilder builder)
        {
            builder.RegisterGeneric(typeof(MyMessagePackSerializer<>)).As(typeof(ISerializer<>)).SingleInstance();

            return builder;
        }

        public static IServiceCollection AddMessagePack(this IServiceCollection services) 
        {

            services.AddSingleton (typeof(MyMessagePackSerializer<>), typeof(ISerializer<>));
            return services;
        }


    }
}
